package com.example.NIO;

import java.nio.ByteBuffer;

/**
 * 使用相应的数据类型 put，应该要按照相应的数据类型获取
 */
public class NIOByteBufferPutGet {
    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(64);
        // 类型化的方式 put
        buffer.putInt(100);
        buffer.putLong(100);
        buffer.putChar('h');
        buffer.putShort((short) 4);

        // 取出
        buffer.flip();
        System.out.println();

        System.out.println(buffer.getInt());
        System.out.println(buffer.getLong());
        System.out.println(buffer.getChar());
        System.out.println(buffer.getShort()/*buffer.getLong() 抛出BufferUnderflowException*/);

    }
}
